[CK_TILE] fmha: Add query padding support to backward pass#3097
Merged
Jeff-Huang merged 4 commits intodevelopfrom Oct 29, 2025
Merged
[CK_TILE] fmha: Add query padding support to backward pass#3097Jeff-Huang merged 4 commits intodevelopfrom
Jeff-Huang merged 4 commits intodevelopfrom
Conversation
c28e4e8 to
97ce9b5
Compare
Introduces support for query sequence padding (q_padding) in the FMHA backward pass kernels. - Passing `seqlen_q_ptr` to the backward kernels to distinguish logical from physical sequence lengths. - Updating `OGradDotO`, `ConvertQGrad`, and `DQDKDV` kernels to respect logical lengths and handle zero-length sequences. - Aligning LSE indexing in the forward kernel with the padded layout for consistency. - Adding a new GTest suite (`test_fmha_bwd_kernel_padding.cpp`) with comprehensive tests for various padding scenarios, including zero-length sequences and deterministic mode.
Add backward q/kv sequence padding unit tests.
Refactor the handling of sequence lengths and padding in the FMHA forward and backward kernels to provide a more unified and flexible interface. - Replaced `seqstart_padded_*_ptr` with a more robust system that uses `seqstart_*_ptr` for physical sequence lengths and introduces `seqlen_*_ptr` and `cu_seqlen_*_ptr` for logical (unpadded) lengths. - Established a clear order of precedence for determining sequence length: cumulative lengths (`cu_seqlen_*_ptr`) take priority, followed by per-sequence lengths (`seqlen_*_ptr`), and finally physical lengths derived from `seqstart_*_ptr`. - Clarified the distinction between "group mode" and "batch mode" and how sequence lengths are handled in each case. - Renamed `cu_seqlen_kv_ptr` to `cu_seqlen_k_ptr` for consistency. - Updated comments and documentation to reflect the new argument structure and usage.
97ce9b5 to
38de35d
Compare
asleepzzz
approved these changes
Oct 29, 2025
Contributor
Author
|
This PR adds some fields to fmha structures: fmha_bwd_args and fmha_fwd_args. The corresponding Aiter PR that adapts these changes is 1212. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
[CK_TILE] fmha: Add query padding support to backward pass
Introduces support for query sequence padding (q_padding) in the FMHA backward pass kernels.
- Passing
seqlen_q_ptrto the backward kernels to distinguish logical from physical sequence lengths.- Updating
OGradDotO,ConvertQGrad, andDQDKDVkernels to respect logical lengths and handle zero-length sequences.- Aligning LSE indexing in the forward kernel with the padded layout for consistency.
- Adding a new GTest suite (
test_fmha_bwd_kernel_padding.cpp) with comprehensive tests for various padding scenarios, Including zero-length sequences in fwd/bwd group modeUnify sequence length and padding handling
- Replaced
seqstart_padded_*_ptrwith a more robust system that usesseqstart_*_ptrfor physical sequence lengths and introducesseqlen_*_ptrandcu_seqlen_*_ptrfor logical (unpadded) lengths.- Established a clear order of precedence for determining sequence
length: cumulative lengths (
cu_seqlen_*_ptr) take priority,followed by per-sequence lengths (
seqlen_*_ptr), and finallyphysical lengths derived from
seqstart_*_ptr.- Clarified the distinction between "group mode" and "batch mode" and
how sequence lengths are handled in each case.
- Renamed
cu_seqlen_kv_ptrtocu_seqlen_k_ptrfor consistency.- Updated comments and documentation to reflect the new argument
structure and usage.
Checklist
Please put an
xinto the boxes that apply. You can also fill these out after creating the PR. If you're not sure, please don't hesitate to ask.clang-formaton all changed filesDiscussion
If this is a relatively large or complex change, feel free to start a discussion by explaining why you chose the solution you did and what alternatives you considered